package com.cskaoyan.controller;

import com.cskaoyan.bean.*;
import com.cskaoyan.bean.bo.StorageListBo;
import com.cskaoyan.bean.vo.StorageListVo;
import com.cskaoyan.service.StorageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;


@RestController
@RequestMapping("admin/storage")
public class StorageController {

    @Autowired
    StorageService storageService;

    @RequestMapping("list")
    public BaseRespVo queryStorageList(StorageListBo storageListBo) {
        if (!storageListBo.isValid()) {
            return BaseRespVo.fail("参数无效，请重新输入");
        }
        StorageListVo storageListVo = storageService.queryStorageList(storageListBo);
        return BaseRespVo.ok(storageListVo);
    }

    @PostMapping("create")
    public BaseRespVo createStorage(MultipartFile file) {
        Storage storage = storageService.createStorage(file);
        return BaseRespVo.ok(storage);
    }

    @PostMapping("delete")
    public BaseRespVo deleteStorage(@RequestBody Storage storage) {
        storageService.deleteStorage(storage);
        return BaseRespVo.ok();
    }

    @PostMapping("update")
    public BaseRespVo updateStorage(@RequestBody Storage storage) {
        storageService.updateStorage(storage);
        return BaseRespVo.ok();
    }
}
